package com.totcy.atom.dialog;

import android.app.Activity;
import android.support.v7.app.AlertDialog;
import android.view.View;

import com.totcy.atom.R;
import com.totcy.atom.utils.WeChatShareUtils;

/**
 * description : 分享dialog
 *
 * @author : Totcy
 * @date : 2018/1/15 16:53
 * @update : 2018/1/15
 */

public class ShareDialog {
    private AlertDialog alertDialog;

    public ShareDialog(Activity activity) {
        View contentView = activity.getLayoutInflater().inflate(R.layout.dialog_share, null);
        contentView.findViewById(R.id.share_weiChart).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onShareTypeClick != null){
                    onShareTypeClick.onItemType(WeChatShareUtils.SHARE_SESSION);
                }
                alertDialog.dismiss();
            }
        });
        contentView.findViewById(R.id.share_moments).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onShareTypeClick != null){
                    onShareTypeClick.onItemType(WeChatShareUtils.SHARE_TIMELINE);
                }
                alertDialog.dismiss();
            }
        });
        contentView.findViewById(R.id.share_collect).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onShareTypeClick != null){
                    onShareTypeClick.onItemType(WeChatShareUtils.SHARE_FAVORITE);
                }
                alertDialog.dismiss();
            }
        });
        alertDialog = new AlertDialog.Builder(activity)
                .setView(contentView)
                .create();

    }

    public ShareDialog setOnItemClick(OnShareTypeClick onShareTypeClick) {

        this.onShareTypeClick = onShareTypeClick;
        return this;
    }

    public void showDialog() {
        if (alertDialog != null) {
            alertDialog.show();
        }
    }

    private OnShareTypeClick onShareTypeClick;

    public interface OnShareTypeClick {
        void onItemType(int type);
    }
}
